home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Páginas y transformaciones / WhatSizeTransform / WhatSizeTransform.cs next >
Encoding:
Text File  |  2002-05-06  |  1.8 KB  |  55 lines

  1. //------------------------------------------------
  2. // WhatSizeTransform.cs ⌐ 2001 by Charles Petzold
  3. //------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class WhatSizeTransform: PrintableForm
  10. {
  11.      public new static void Main()
  12.      {
  13.           Application.Run(new WhatSizeTransform());
  14.      }
  15.      public WhatSizeTransform()
  16.      {
  17.           Text = "┐QuΘ tama±o? con TransformPoints";
  18.      }
  19.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  20.      {
  21.           Brush   brush = new SolidBrush(clr);
  22.           int     y     = 0;
  23.           Point[] apt   = { new Point(cx, cy) };
  24.  
  25.           grfx.TransformPoints(CoordinateSpace.Device, 
  26.                                CoordinateSpace.Page, apt);
  27.  
  28.           DoIt(grfx, brush, ref y, apt[0], GraphicsUnit.Pixel);
  29.           DoIt(grfx, brush, ref y, apt[0], GraphicsUnit.Display);
  30.           DoIt(grfx, brush, ref y, apt[0], GraphicsUnit.Document);
  31.           DoIt(grfx, brush, ref y, apt[0], GraphicsUnit.Inch);
  32.           DoIt(grfx, brush, ref y, apt[0], GraphicsUnit.Millimeter);
  33.           DoIt(grfx, brush, ref y, apt[0], GraphicsUnit.Point);
  34.      }
  35.      void DoIt(Graphics grfx, Brush brush, ref int y, 
  36.                Point pt, GraphicsUnit gu)
  37.      {
  38.           GraphicsState gs = grfx.Save();
  39.  
  40.           grfx.PageUnit  = gu;
  41.           grfx.PageScale = 1;
  42.  
  43.           PointF[] aptf = { pt };
  44.  
  45.           grfx.TransformPoints(CoordinateSpace.Page, 
  46.                                CoordinateSpace.Device, aptf);
  47.  
  48.           SizeF sizef = new SizeF(aptf[0]);
  49.           grfx.Restore(gs);
  50.  
  51.           grfx.DrawString(gu + ": " + sizef, Font, brush, 0, y);
  52.           y += (int) Math.Ceiling(Font.GetHeight(grfx));
  53.      }
  54. }
  55.